package com.iu.eblood.daoImpl;

import java.util.List;

import javax.management.Query;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.iu.eblood.dao.GenericDao;
import com.iu.eblood.daoInterfaces.InformativeMessageDao;
import com.iu.eblood.model.Informativemessage;

@Repository("InformativeMessageDaoImpl")
public class InformativeMessageDaoImpl extends GenericDao<Informativemessage,Long>
implements InformativeMessageDao{

	public InformativeMessageDaoImpl() {
	super(Informativemessage.class);
	}

	//All InformativeMessages
	public List<Informativemessage> getAllActiveMessages() {
		
		Session session=getHibernateTemplate().getSessionFactory().getCurrentSession();
		Criteria c=session.
				createCriteria(Informativemessage.class).
				add(Restrictions.eq("isactive", "1"));
		
		List<Informativemessage> lst=c.list();
		
		return c.list();
	}
	
	//Urgent Messages which can be for Institution Stock State or Personal
	public List<Informativemessage> getAllUrgetMessages()
	{
		
		Session session=getHibernateTemplate().getSessionFactory().getCurrentSession();
		List<Informativemessage> lst=session.createQuery("from Informativemessage as IM where typeid=:UrgentType or typeid=:InstitutionType").
				setLong("UrgentType",1).setLong("InstitutionType",2).list();
		
		return lst;
	}
	
	
	//General Messages By Institutions
	public List<Informativemessage> getAllGeneralMessages()
	{
		
		Session session=getHibernateTemplate().getSessionFactory().getCurrentSession();
		List<Informativemessage> lst=session.createQuery("from Informativemessage as IM where typeid=:GeneralType").
				setLong("GeneralType",3L).list();
		
		return lst;
	}
}
